<?php

	error_reporting(E_ALL);
	
	class Feeder {
	
		function Feeder(){
			
			include($_SERVER['DOCUMENT_ROOT'] . '/include/header.class.php');
			include($_SERVER['DOCUMENT_ROOT'] . '/include/parse.class.php');
			include($_SERVER['DOCUMENT_ROOT'] . '/include/menu.class.php'); 
			include($_SERVER['DOCUMENT_ROOT'] . '/include/db.class.php'); new Mysql;
		
		}
		
		
		function ShowNews($max=3){
			
			
			echo Header::CompileHeader('November 2007, A fresh product release (Event Manager). Some noticable site updates soon!');
			$quicklist = array();unset($GLOBALS['str']);
			$month = date('m');$year = date('Y');


			for($m=0; $m<4; $m++){
		
				$end = date('Y-m-t H:i:s', mktime(23,59,59,$month,1,$year));
				$start = date('Y-m-01', mktime(0,0,0,$month,1,$year));
			
				$rr = Mysql::query('SELECT `Title`,`Date`,`Article` FROM `feed` where `Date` between \''.$start.'\' and \''.$end.'\' ORDER BY `Date` DESC', FALSE);

			
				if(!(mysql_num_rows($rr) < 1)){
				
					echo '<h2 class="month">'.date('F', mktime(0, 0, 0, $month, 1, $year)).'</h2>';
					$quicklist[] = '<h2 class="monthq">'.date('F', mktime(0, 0, 0, $month, 1, $year)).'</h2>';
				
						while($arr = Mysql::fetch_array($rr)){
							$link = str_replace(' ','_',$arr["Title"]);
							$quicklist[] = '<a href="/news/'.$link.'">'.$arr["Title"].'</a>';
							
							list($y,$mi,$d) = split('-',$arr["Date"]);

							echo Parser::Parse(array('template'=>'/template/feed/ShowNews.tpl','bbcode'=>TRUE),
								array('{TITLE}','{DATE}','{ARTICLE}','{URL}'),
								array($arr["Title"],date('F jS Y',mktime(0,0,0,$mi,$d,$y)),$arr["Article"],$link));
								
							unset($y,$mi,$d);
							
						}
				}
		
				$month--;
			}
			
			echo '<div class="premonth"><a href="#">View previous months.</a></div>';
			$quicklist[] = '<a href="/news/older"><strong>previous months.</strong></a>';

			Mysql::close();
			echo Menu::CallFunctions($quicklist,'news');

		
		}
		
		function ReadMore($title){
			
			if(strstr($_SERVER['REQUEST_URI'], '%20')){
				header( "HTTP/1.1 301 Moved Permanently" );
				header( "Location: http://www.myphpdigest.com".str_replace('%20','_',$_SERVER['REQUEST_URI']) );
			}

			$arr = Mysql::query('SELECT `Title`,`Date`,`Article` FROM `feed` WHERE `Title` = \''.str_replace('_',' ',$title).'\'', TRUE);
			
			if(empty($arr['Title'])){
				$arr['Title'] = 'Article not found!';
				$arr['Article'] = 'Error: Article not found!';
			}
			
            echo Header::CompileHeader($arr["Title"],substr($arr["Article"], 0, 300));
			
			if($arr['Title']=='Article not found!'){
			
				echo '<h1>Error</h1><span id="date">Page not found</span><p>The following page never existed. If you think their has been internal errors which present this page then please <a href="http://myphpdigest.com/contact">click here to report the page that this occurs on</a></p>';
			
			} else {
			
				// Change Date
				list($y,$m,$d) = split('-',$arr["Date"]);
				$arr["Date"] = date('jS F Y',mktime(0,0,0,$m,$d,$y));
				$link = str_replace(' ','_',$arr["Title"]);
				
				unset($GLOBALS['str']);
				echo Parser::Parse(	array('template'=>'/template/feed/ShowNews.tpl','bbcode'=>TRUE),
								array('{TITLE}','{DATE}','{ARTICLE}','{URL}'),
								array($arr["Title"],$arr["Date"],$arr["Article"],$link));
			}

			
			Mysql::close();
			echo Menu::CallFunctions(array($arr["Title"]));
			
		}
		
	
	}

?>